package org.matrix.base
{

	public class Matrix5D extends Matrix4D
	{
		public function Matrix5D(depth:uint){super(depth); 	d5Lenght  = d4Lenght * depth;}
		
		override public function get dimensions():uint		{return 5}
		
		internal var d5Lenght:uint;
		protected var d5Index:uint;
		internal var d5Dirty:Boolean;
		internal var d5:Vector.<Vector.<Vector.<Vector.<Vector.<Number>>>>>;
		override protected function init():void
		{
			d5 = new Vector.<Vector.<Vector.<Vector.<Vector.<Number>>>>>(depth,true);
			for (var i:uint; i < depth; i++)
			{
				super.init();
				d5[i] = d4;
			}
		}
		
		override public function getElement( ... keys:Array):Number				{return d5[keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()]}
		override public function setElement(value:Number, ... keys:Array):void	{d5[keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()] = value}
		
		override public function get index():uint	{return d5Index * d4Lenght + super.index}
		
		override protected function validate():void
		{
			if (d4Dirty)
			{
				d4 = d5[d5Index];
				d4Dirty = false;
				d3Dirty = true;
			}
			return super.validate();
		}
		
		protected function d6Inc(recursive:Boolean = false):void
		{
			if (recursive)
				d5Index = 0;
			else
				throw new Error('')
		}
		final override protected function d5Inc(recursive:Boolean = false):void
		{
			if (++ d5Index == depth)
				d6Inc(d5Dirty = true);
			if (recursive)
				d4Index = 0;
		}
	}
}